<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>任务列表</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 1000px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #f8f9fa;
            font-weight: bold;
        }
        tr:hover {
            background-color: #f5f5f5;
        }
        .status-pending {
            color: #856404;
            font-weight: bold;
        }
        .status-running {
            color: #004085;
            font-weight: bold;
        }
        .status-completed {
            color: #155724;
            font-weight: bold;
        }
        .status-failed {
            color: #721c24;
            font-weight: bold;
        }
        .nav-links {
            text-align: center;
            margin-top: 20px;
        }
        .nav-links a {
            display: inline-block;
            margin: 0 10px;
            color: #007bff;
            text-decoration: none;
        }
        .nav-links a:hover {
            text-decoration: underline;
        }
        .no-tasks {
            text-align: center;
            color: #6c757d;
            font-style: italic;
            padding: 20px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>任务列表</h1>
        
        {% if tasks %}
            <table>
                <thead>
                    <tr>
                        <th>任务ID</th>
                        <th>状态</th>
                        <th>图片目录</th>
                        <th>音频目录</th>
                        <th>输出目录</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for task in tasks.values() | reverse %}
                        <tr>
                            <td>{{ task.id }}</td>
                            <td class="status-{{ task.status }}">
                                {% if task.status == 'pending' %}等待中
                                {% elif task.status == 'running' %}运行中
                                {% elif task.status == 'completed' %}已完成
                                {% elif task.status == 'failed' %}失败
                                {% endif %}
                            </td>
                            <td>{{ task.images_dir | truncate(30) }}</td>
                            <td>{{ task.audios_dir | truncate(30) }}</td>
                            <td>{{ task.output_dir | truncate(30) }}</td>
                            <td>
                                <a href="{{ url_for('task_status', task_id=task.id) }}">查看详情</a>
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        {% else %}
            <div class="no-tasks">
                <p>暂无任务</p>
            </div>
        {% endif %}
        
        <div class="nav-links">
            <a href="{{ url_for('index') }}">返回首页</a>
        </div>
    </div>
</body>
</html>